package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 8:22 PM
 */
object Test17_Extends {
  def main(args: Array[String]): Unit = {
    val student = new Student17("zs", 20)
    student.sayHi()

    val person: Person17 = new Student17("zsf", 21)
    person.sayHi()

    println(s"student is Student17: ${student.isInstanceOf[Student17]}")
    println(s"person is Person17: ${person.isInstanceOf[Person17]}")
    println(s"person is Student17: ${person.isInstanceOf[Student17]}")

    val person2 = new Person17("ls", 22)
    println(s"person2 is Student17: ${person2.isInstanceOf[Student17]}")

    // 类型转换
    if (person.isInstanceOf[Student17]) {
      val newStudent: Student17 = person.asInstanceOf[Student17]
      newStudent.study()
    }

    // 2.测试枚举类
    println(WorkDay.MONDAY)
  }
}

class Person17(val name: String, val age: Int) {
  def sayHi(): Unit = {
    println(s"hi from person ${name}")
  }
}
class Student17(name: String, age: Int) extends Person17(name, age) {
  override def sayHi(): Unit = {
    println(s"hi from student ${name}")
  }

  def study(): Unit = {
    println("student study")
  }
}

// 定义枚举类对象
object  WorkDay extends Enumeration {
  val MONDAY = Value(1, "Monday")
  val TUESDAY = Value(2, "Tuesday")
}

// 定义应用类
object TestApp extends App {
  println("app start")

  type MyString = String
  val a: MyString = "aabc"
  println(a)
}